package dxgi;

import dxgi.DXGI.DXGI_FORMAT;

import org.bridj.Pointer;
import org.bridj.ValuedEnum;

import static org.bridj.Pointer.*;
import org.bridj.ann.Library;
import org.bridj.ann.Runtime;
import org.bridj.ann.Virtual;
import org.bridj.cpp.com.COMRuntime;
import org.bridj.cpp.com.IID;
import org.bridj.cpp.com.IUnknown;
/**
 * <i>native declaration : DXGI.h:1536</i><br>
 * Error: Conversion Error : uuid("aec22fb8-76f3-4639-9be0-28eb43a67a2e") novtable struct IDXGIObject {<br>
 * 	/// Original signature : <code>int SetPrivateData(const GUID&, UINT, const void*)</code><br>
 * 	virtual int SetPrivateData(const GUID& Name, UINT DataSize, const void* pData);<br>
 * 	/// Original signature : <code>int SetPrivateDataInterface(const GUID&, const IUnknown*)</code><br>
 * 	virtual int SetPrivateDataInterface(const GUID& Name, const IUnknown* pUnknown);<br>
 * 	/// Original signature : <code>int GetPrivateData(const GUID&, UINT*, void*)</code><br>
 * 	virtual int GetPrivateData(const GUID& Name, UINT* pDataSize, void* pData);<br>
 * 	/// Original signature : <code>int GetParent(const IID&, void**)</code><br>
 * 	virtual int GetParent(const IID& riid, void** ppParent);<br>
 * } (Cannot find parent IUnknown of struct uuid("aec22fb8-76f3-4639-9be0-28eb43a67a2e") novtable struct IDXGIObject {<br>
 * 	/// Original signature : <code>int SetPrivateData(const GUID&, UINT, const void*)</code><br>
 * 	virtual int SetPrivateData(const GUID& Name, UINT DataSize, const void* pData);<br>
 * 	/// Original signature : <code>int SetPrivateDataInterface(const GUID&, const IUnknown*)</code><br>
 * 	virtual int SetPrivateDataInterface(const GUID& Name, const IUnknown* pUnknown);<br>
 * 	/// Original signature : <code>int GetPrivateData(const GUID&, UINT*, void*)</code><br>
 * 	virtual int GetPrivateData(const GUID& Name, UINT* pDataSize, void* pData);<br>
 * 	/// Original signature : <code>int GetParent(const IID&, void**)</code><br>
 * 	virtual int GetParent(const IID& riid, void** ppParent);<br>
 * })<br>
 * This file was autogenerated by <a href="http://jnaerator.googlecode.com/">JNAerator</a>,<br>
 * a tool written by <a href="http://ochafik.free.fr/">Olivier Chafik</a> that <a href="http://code.google.com/p/jnaerator/wiki/CreditsAndLicense">uses a few opensource projects.</a>.<br>
 * For help, please visit <a href="http://nativelibs4java.googlecode.com/">NativeLibs4Java</a> or <a href="http://bridj.googlecode.com/">BridJ</a> .
 */
@IID("310d36a0-d2e7-4c0a-aa04-6a9d23b8886a") 
@Library("dxgi") 
@Runtime(COMRuntime.class)
public class IDXGISwapChain extends IDXGIDeviceSubObject {
	public IDXGISwapChain() {
		super();
	}
	public IDXGISwapChain(Pointer pointer) {
		super(pointer);
	}
	@Virtual(0) 
	public native int Present(int SyncInterval, int Flags);
	//@Deprecated
	@Virtual(1) 
	public native int GetBuffer(int Buffer, Pointer<Byte> riid, Pointer<Pointer<? > > ppSurface);
	//@Deprecated
	@Virtual(2) 
	public native int SetFullscreenState(int Fullscreen, Pointer<IDXGIOutput > pTarget);
	//@Deprecated
	@Virtual(3) 
	public native int GetFullscreenState(Pointer<Integer > pFullscreen, Pointer<Pointer<IDXGIOutput > > ppTarget);
	@Virtual(4) 
	public native int GetDesc(Pointer<DXGI_SWAP_CHAIN_DESC> pDesc);
	@Virtual(5)
	public native int ResizeBuffers(int BufferCount, int Width, int Height, ValuedEnum<DXGI_FORMAT> NewFormat, int SwapChainFlags);
	//@Deprecated
	@Virtual(6) 
	public native int ResizeTarget(Pointer<DXGI_MODE_DESC> pNewTargetParameters);
	//@Deprecated
	@Virtual(7) 
	public native int GetContainingOutput(Pointer<Pointer<IDXGIOutput > > ppOutput);
	//@Deprecated
	@Virtual(8) 
	public native int GetFrameStatistics(Pointer<DXGI_FRAME_STATISTICS > pStats);
	//@Deprecated
	@Virtual(9) 
	public native int GetLastPresentCount(Pointer<Integer > pLastPresentCount);
	
	// "Javanized" methods
	public <T extends IUnknown> T GetBuffer(int Buffer, Class<T> klass) {
		// Get GUID of class
		Pointer<Byte> guid = COMRuntime.getIID(klass);
		
		// Get back buffer pointer
		Pointer<Pointer<?>> pp = allocatePointer();
		
		try {
			int result = this.GetBuffer(Buffer, guid, pp);
			if(result != 0) {
				throw new DXGIException("Could not get back buffer from swap chain", result);
			}
			
			return pp.get().getNativeObject(klass);
			
		} finally {
			pp.release();
		}
	}
	
	public final int GetLastPresentCount() {
		Pointer<Integer> pp = allocate(Integer.class);
		try {
			int result = this.GetLastPresentCount(pp);
			if(result != 0) {
				throw new DXGIException("Could not get last present count", result);
			}
			
			return pp.get();
		} finally {
			pp.release();
		}
	}
	
	public final DXGI_FRAME_STATISTICS GetFrameStatistics() {
		Pointer<DXGI_FRAME_STATISTICS> pp = allocate(DXGI_FRAME_STATISTICS.class);
		try {
			int result = this.GetFrameStatistics(pp);
			if(result != 0) {
				throw new DXGIException("Could not get frame statistics", result);
			}
			
			return pp.get();
		} finally {
			pp.release();
		}
	}
	
	public final IDXGIOutput GetContainingOutput() {
		Pointer<Pointer<IDXGIOutput>> pp = allocatePointer(IDXGIOutput.class);
		try {
			int result = this.GetContainingOutput(pp);
			if(result != 0) {
				throw new DXGIException("Could not get monitor output", result);
			}
			
			return pp.get().getNativeObject(IDXGIOutput.class);
		} finally {
			pp.release();
		}
	}
	
	public final void ResizeTarget(DXGI_MODE_DESC newTargetParameters) {
		int result = this.ResizeTarget(pointerTo(newTargetParameters));
		if(result != 0) {
			throw new DXGIException("Could not resize target", result);
		}
	}
	
	public final void SetFullscreenState(int Fullscreen, IDXGIOutput target) {
		int result = this.SetFullscreenState(Fullscreen, pointerTo(target));
		if(result != 0) {
			throw new DXGIException("Could set fullscreen state", result);
		}
	}
	
	public final boolean GetFullscreenState(IDXGIOutput target) {
		Pointer<Integer> pInt = allocateInt();
		try {
			int result = this.GetFullscreenState(pInt, pointerToPointer(pointerTo(target)));
			if(result != 0) {
				throw new DXGIException("Could get fullscreen state", result);
			}
			
			return pInt.get() > 0 ? true : false;
		} finally {
			pInt.release();
		}
	}
}
